package com.springdemo.taskexecutor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
//在spring中可以通过
public class TaskExecutorConfig implements AsyncConfigurer {
    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor threadPoolTaskExecutor=new ThreadPoolTaskExecutor();
        //线程池设置核心线程池大小
        threadPoolTaskExecutor.setCorePoolSize(8);
        //设置核心线程池最大值
        threadPoolTaskExecutor.setMaxPoolSize(15);
        //  <!-- 队列最大长度 >=mainExecutor.maxSize -->
        threadPoolTaskExecutor.setQueueCapacity(300);
        threadPoolTaskExecutor.initialize();
        return  threadPoolTaskExecutor;
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return null;
    }
}
